import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class tryForm extends MIDlet implements CommandListener{
	private Display dis;
	private Command cmdback;
	private Command cmdexit;
	private Command cmdselect;
	private Command cmdok;
	private TextField tfname;
	private TextField tfpswd;
	private Alert error;
	private Form form;
	public tryForm() {
		// TODO Auto-generated constructor stub
		form = new Form("AV女星选择系统");
		tfname = new TextField("Name:","",10,TextField.ANY);
		tfpswd = new TextField("Pswd:","",10,TextField.ANY|TextField.PASSWORD);
		cmdback = new Command("back",Command.BACK,0);
		cmdexit = new Command("exit",Command.EXIT,1);
		cmdselect = new Command("select",Command.ITEM,2);
		cmdok = new Command("ok",Command.OK,3);
	}
	

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		dis = Display.getDisplay(this);
		form.append(tfname);
		form.append(tfpswd);
		form.addCommand(cmdok);
		form.addCommand(cmdexit);
		form.setCommandListener(this);
		dis.setCurrent(form);
	}


	public void commandAction(Command cmd, Displayable d) {
		// TODO Auto-generated method stub
		if(cmd == cmdok)
		{
			String nameitem = tfname.getString();
			String pswditem = tfpswd.getString();
			if(nameitem.trim().length()==0)
			{
				error = new Alert("error","用户名不能为空!",null,AlertType.ERROR);
				dis.setCurrent(error,form);
			}
			else if(pswditem.trim().length()==0)
			{
				error = new Alert("error","密码不能为空！",null,AlertType.ERROR);
				dis.setCurrent(error, form);
			}
			else if(nameitem.equals("admin")&&pswditem.equals("admin"))
			{
				error = new Alert("恭喜","成功登录！",null,AlertType.ERROR);
				dis.setCurrent(error, form);
			}
			else
			{
				error = new Alert("error","用户名或者密码错误",null,AlertType.ERROR);
				dis.setCurrent(error, form);
			}
		}
		else if(cmd == cmdexit)
		{
			notifyDestroyed();
		}
		
	}

}
